function btnback() {
    window.location.href = "/product/index"
}
function btnadd() {
    window.location.href = "/product/createOrEdit"
}
function btnedit(id) {
    window.location.href = `/product/createOrEdit/${id}`
}
function btndel(id) {
    if (confirm("确定删除？")) {
        window.location.href = `/product/delete/${id}`
    }
}
function btnsave() {
    var productName = $("[name=productName]").val();
    var supplier = $("[name=supplier]").val();
    var price = $("[name=price]").val();
    var stock = $("[name=stock]").val();
    var remarks = $("[name=remarks]").val();
    var id = $("[name=id]").val();
    var categoryId = 1;

    var obj = {
        productName,
        supplier,
        price,
        stock,
        remarks,
        id,
        categoryId,
    }
    $.post("/product/save", obj, function () {
        alert("保存成功!");
        window.location.href = "/product/index";
    })
}

function btnquery(){
    var word = $("[name=keyword]").val()
    var obj={
        word
    }
    $.post("/product/query",obj,function(res){
        $("[name=tbdata]").html("");
        res.forEach(item => {
            var html=`
            <tr>
                    <td>${item.id}</td>
                    <td>${item.productName}</td>
                    <td>${item.supplier}</td>
                    <td>${item.price}</td>
                    <td>${item.supplier}</td>
                    <td>${item.remarks}</td>
                    <td>
                        <button onclick="btnedit(${item.id})">修改</button>
                        <button onclick="btndel(${item.id})">刪除</button>
                    </td>
                </tr>
                `
                $("[name=tbdata]").append(html);
        });
    })
}